package com.xcalendar.service.rest.converter;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.xcalendar.database.table.Event;

@XmlRootElement(name = "event")
public class EventConverter {
	private Event entity = null;

	public EventConverter() {
		entity = new Event();
	}
	public Event getEvent() {
		return entity;
	}
	public EventConverter(Event entity) {
		this.entity = entity;
	}
	
	@XmlElement
	public String getKey() {
		return KeyFactory.keyToString(entity.getKey());
	}

	public void setKey(String key) {
		entity.setKey(KeyFactory.stringToKey(key));
	}
	@XmlElement
	public String getUserKey() {
		return KeyFactory.keyToString(entity.getUserKey());
	}

	public void setUserKey(String key) {
		entity.setUserKey(KeyFactory.stringToKey(key));
	}
	
	@XmlElement
	public String getTitle() {
		return entity.getTitle();
	}

	public void setTitle(String title) {
		entity.setTitle(title);
	}
	@XmlElement
	public String getStartTime() {
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return time.format(entity.getStartTime());
	}

	public void setStartTime(Date startTime) {
		entity.setStartTime(startTime);
	}
	@XmlElement
	public String getEndTime() {
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return time.format(entity.getEndTime());
	}

	public void setEndTime(Date endTime) {
		entity.setEndTime(endTime);
	}
	@XmlElement
	public String getRemindTime() {
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (entity.getRemindTime()!=null) {
			return time.format(entity.getRemindTime());
		}
		return null;
	}

	public void setRemindTime(Date remindTime) {
		entity.setRemindTime(remindTime);
	}
	@XmlElement
	public boolean isImportant() {
		return entity.isImportant();
	}

	public void setImportant(boolean important) {
		entity.setImportant(important);
	}
	@XmlElement
	public String getDescription() {
		return entity.getDescription();
	}

	public void setDescription(String description) {
		entity.setDescription(description);
	}
	@XmlElement
	public String getLocationKey() {
		if (entity.getLocationKey() != null) {
			return KeyFactory.keyToString(entity.getLocationKey());
		}else {
			return null;
		}
		
	}

	public void setLocation(String locationKey) {
		entity.setLocationKey(KeyFactory.stringToKey(locationKey));
	}
}
